from rest_framework.pagination import PageNumberPagination

# 重写JWT方法
from rest_framework.response import Response


def jwt_response_payload_handle(token, user=None, request=None):
    return {
        'token': token,
        'username': user.username,
        'id': user.id,
    }


class PageNum(PageNumberPagination):
    # page_query_param = 'pagesize'
    max_page_size = 10
    # 分页器参数，每页数量关键字
    page_size_query_param = 'pagesize'
    # 指定分页返回结果的方法

    def get_paginated_response(self, data):
        # return Response(OrderedDict([
        #     ('count', self.page.paginator.count),
        #     ('next', self.get_next_link()),
        #     ('previous', self.get_previous_link()),
        #     ('results', data)
        # ]))
        return Response(
            {
                'count':self.page.paginator.count,
                'lists':data,
                'page':self.page.number,
                'pages':self.page.paginator.num_pages,
                'pagesize':self.max_page_size
            }
        )